<?php

class StudentController extends Zend_Controller_Action
{

    public function init()
    {
        $this->_helper->contextSwitch()
                ->addActionContext('getJsonStudentDetail', array('json'))
                ->initContext();
    }

    public function indexAction()
    {
        $objStudent = new Application_Model_Student();
        $arrStudentList = $objStudent->getStudentList();
        $this->view->assign('arrStudentList', $arrStudentList);
    }

    public function signAction()
    {
        if ($this->getRequest()->getMethod() == 'POST') {
            $arrStudentInfo = $this->getParam('Student', array());
            $objStudent = new Application_Model_Student();
            $objStudent->insertStudent($arrStudentInfo);
        }
    }

    public function editAction()
    {
        if ($this->getRequest()->getMethod() == 'POST') {
            $intID = $this->getParam('Student[id]', 0);
            $arrStudentInfo = $this->getParam('Student', array());
            $objStudent = new Application_Model_Student();
            $objStudent->updateStudent($arrStudentInfo, $intID);
        } else {
            $intID = $this->getParam('id', 0);
            $objStudent = new Application_Model_Student();
            $StudentDetail = $objStudent->getStudentDetail($intID);
            $this->view->assign('StudentDetail', $StudentDetail);
        }
    }

    public function deleteAction()
    {
        $this->_helper->viewRenderer->setNoRender(true);
        $intID = $this->getParam('id', 0);
        $objStudent = new Application_Model_Student();
        $objStudent->deleteStudent($intID);
    }

    public function restAction()
    {
        $server = new Zend_Rest_Server();
	$server->addFunction('Test');
	$server->handle();
        exit;
    }
    
    private function Test(){
        return "Hello!";
    }


}


